php curl数据传不过去该怎样处理 |
您所在的位置:网站首页 › php curl timeout › php curl数据传不过去该怎样处理 |
当前位置:首页 » 编程设计 » 正文
php curl数据传不过去该怎样处理
2023年04月08日6shihaiming
本文操作环境:Windows7系统、PHP7.1版,DELL G3电脑 php curl数据传不过去怎么办? php curl post提交数据失败解决方法 代码如下: function http_req($http_type, $method, $url, $data) { $ch = curl_init(); if (strstr($http_type, 'https')) { curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); } if ($method == 'post') { curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); } else { $url = $url . '?' . $data; } curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 100000);//超时时间 try { $ret = curl_exec($ch); } catch (Exception $e) { curl_close($ch); return json_encode(array('ret' => 0, 'msg' => 'failure')); } curl_close($ch); return $ret; } //第一种提交方式在遇到post_data 中包含@等一些符号时会出现提交失败的情况 $url = "http://localhost/web_services.php"; $post_data = array ("username" => "bob","key" => "12345"); $response = http_req('http', 'post', $url, $post_data ); //第二种提交方式可以避免 $url = "http://localhost/web_services.php"; $post_data = "username=bob&key=12345"; $response = http_req('http', 'post', $url, $post_data ); 本文参考链接:https://www.yisu.com/zixun/612428.html 上一篇: php中支持不支持mysql_query()函数 下一篇: 怎么用PHP代码采集微信公众号的文章 PHP 文章来源:ITGUEST,欢迎分享,转载请保留出处 原文地址:https://www.itguest.com/post/biefi2b2.html 阅读延展 怎么用php判断是否为空文件夹如何利用PHP+Mysql实现增删改查PHP中如何以填充方式来创建数组PHP怎么计算两个给定整数值的总和以及两个值相同时返回其总和的三倍php怎么利用header跳转无效的解决方法centOS中各版本php的示例分析PHP如何使用is_dir()函数php如何利用foreach语句修改键值怎么在Windows中搭建PHP本地开发环境php怎么实现小型留言本功能php如何利用header()禁止缓存php数组键名怎么转换为变量名 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |